package com.example.studytest.Controller.OpenData;

import com.example.studytest.Entity.OpenData.WebSite;
import com.example.studytest.Repository.OpenData.DownloadPerRepository;
import com.example.studytest.Repository.OpenData.WebSiteRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/webSite")
public class WebSiteController {
    @Autowired
    private WebSiteRepository webSiteRepository;

    @Autowired
    private DownloadPerRepository downloadPerRepository;

    @PostMapping("/save")
    public void saveWebsiteInfo(@RequestBody WebSite webSite){
        System.out.println(webSite.getViews());
        String downloads = downloadPerRepository.countAllDPer()+"";
        webSite.setDownloads(downloads);

        WebSite webSite1 = webSiteRepository.save(webSite);
        System.out.println(webSite1.getDownloads());
        System.out.println(webSite1.getViews());
    }

    @GetMapping("/getData")
    public WebSite getWebsiteInfo(){
        return webSiteRepository.FindWebInfo();
    }




}
